#pragma once

#include "BasicType.h"


namespace LightPlayer{

	class TimelineObject;

	template <typename T>
	class pool{
		array<T*> list;
		array<T*> freeList;

		pool(const pool& o){}
	public:
		pool(){}
		~pool(){
			clear();
		}
		void clear(){
			for (uint32 i = 0; i < list.size(); i++){
				delete list[i];
			}
			list.clear();
			freeList.clear();
		}
		T* getNew(){
			T* newobj = NULL;
			if(freeList.size() > 0){
				newobj = freeList.back();
				freeList.pop_back();
			}
			else{
				newobj = new T();
				list.push_back( newobj );
			}
			return newobj;	
		}
		void FreeObject(T* p){
			freeList.push_back(p);
		}
	};

};